package com.study.webapp.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Leet_22 {

	public static void main(String[] args) {
		System.out.println(Arrays.asList(getKuoHao(3)));
	}

	public static List<String> getKuoHao(int n) {
		List<String> ans = new ArrayList<>();
		getList(ans, "", 0, 0, n);
		return ans;
	}

	public static void getList(List<String> ans, String cur, int open, int close, int max) {
		if (cur.length() == max * 2) {
			ans.add(cur);
			return;
		}
		if (open < max) {
			getList(ans, cur + "(", open + 1, close, max);
		}
		if (close < open) {
			getList(ans, cur + ")", open, close + 1, max);
		}
	}

}
